﻿using System;
using System.Collections.Generic;
using System.Text;
using YmSoft.Kblog.Model;
using YmSoft.Kblog.Utility;
using System.Data;
using System.Data.SqlClient;
using YmSoft.Kblog.IDAL;

namespace YmSoft.Kblog.DAL
{
    public class LimitIPService : ILimitIPService
    {
        K_LimitIP limitip = new K_LimitIP();
        public LimitIPService()
        {

        }
        /// <summary>
        /// 限制登录IP
        /// </summary>
        /// <returns></returns>
        public List<K_LimitIP> GetAllLimitIP()
        {
            List<K_LimitIP> list = new List<K_LimitIP>();
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from K_LimitIP ");
            sql.Append(" where RemoveDate > GETDATE() ");
            DataTable Dt = SQLHelper.ExecuteNonDataTable(sql.ToString());
            if (Dt.Rows.Count != 0)
            {
                for (int i = 0; i < Dt.Rows.Count; i++)
                {
                    K_LimitIP limit = new K_LimitIP();
                    limit.ID = Convert.ToInt32(Dt.Rows[i]["ID"]);
                    limit.IP = Dt.Rows[i]["IP"].ToString();
                    limit.LimitDate = Convert.ToDateTime(Dt.Rows[i]["LimitDate"]);
                    limit.RemoveDate = Convert.ToDateTime(Dt.Rows[i]["RemoveDate"]);
                    limit.Operate = Dt.Rows[i]["Operate"].ToString();
                    limit.Description = Dt.Rows[i]["Description"].ToString();
                    list.Add(limit);
                }
            }
            else
            {
                list = null;
            }
            return list;
        }
        public int LimitLoginCount()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select count(*) from K_LimitIP");
            int val = (int)SQLHelper.ExecuteNonScalar(sql.ToString());
            return val;
        }

        #region ILimitIPService 成员


        public SqlDataAdapter LimitLoginList()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from K_LimitIP");
            SqlDataAdapter da = SQLHelper.ExecuteNonSqlDataAdapter(sql.ToString());
            return da;
        }

        #endregion
    }
}
